package cn.aylog.test;

import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class Demo {

    @Test
    public void run() {
        Jedis jedis = new Jedis("192.168.148.128",6379);
        jedis.auth("123");

        jedis.set("name", "aylog");
        String name = jedis.get("name");
        System.out.println(name);
        jedis.close();
    }

    @Test
    public void run2() throws IOException {
        Set<HostAndPort> set = new HashSet<>();
        set.add(new HostAndPort("192.168.148.71", 7001));
        set.add(new HostAndPort("192.168.148.72", 7002));
        set.add(new HostAndPort("192.168.148.73", 7003));
        set.add(new HostAndPort("192.168.148.74", 7004));
        set.add(new HostAndPort("192.168.148.75", 7005));
        set.add(new HostAndPort("192.168.148.76", 7006));
        JedisCluster cluster = new JedisCluster(set);
        String k1 = cluster.get("k1");
        System.out.println(k1);

        cluster.close();

    }

}
